package com.broada.apm.dao;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.broada.apm.model.Alert;
import com.broada.apm.model.ConfigItem;
import com.broada.apm.model.PagingList;

public interface AlertDao {

	/**
	 * 添加告警
	 * @param alert
	 */
	public void addAlert(Alert alert);
	
	/**
	 * 更新告警
	 * @param alert
	 */
	public void updateAlert(Alert alert);
	
	/**
	 * 删除告警
	 * @param alert
	 */
	public void deleteAlert(Alert alert);
	
	/**
	 * 根据条件分页查询时间段内告警
	 * 注：alert.status and alert.clearStatus=-1全部即不作为条件
	 * @param alert
	 * @param pageIndex 
	 * @param pageSize 
	 * @param endDate 
	 * @param startDate 
	 */
	public PagingList<Alert> getAlert(Alert alert, int pageIndex, int pageSize,
			Date startDate, Date endDate, String sortField, String sortBy);

	/**
	 * 根据告警等级获取未处理(status=0)告警个数
	 * @param severity
	 * @return
	 */
	public int getAlertCountBySeverity(int severity);

	/**
	 * 根据id获取告警
	 * @param id
	 * @return
	 */
	public Alert getAlertById(String id);

	/**
	 * 查询产生告警的主机数
	 * @param severity
	 * @return
	 */
	public int getServerCountBySeverity(int severity);

	public List<Alert> getAlertBySeverityAndServiceId(String id, int serverity);

	/**
	 * 更新告警状态
	 * @param alert
	 */
//	public void updateAlertStaus(Alert alert);
	
	/**
	 * 添加配置阈值信息
	 * @param configItem
	 */
	public void addAlertThreshold(ConfigItem configItem);
	
	/**
	 * 更新配置阈值信息
	 * @param configItem
	 */
	public void updateAlertThreshold(ConfigItem configItem);
	
	/**
	 * 删除配置阈值信息
	 * @param configItem
	 */
	public void deleteAlertThreshold(ConfigItem configItem);
	
	/**
	 * 根据key查询阈值配置信息
	 * @param key
	 * @return
	 */
	public ConfigItem getAlertThreshold(String key);
	
	/**
	 * 根据key模糊查询阈值配置信息
	 * @param key
	 * @return
	 */
	public List<ConfigItem> getAlertThresholdLikeKey(String key);

	public int getAlertCountBySeverityCondition(int severity, String appId, String serviceId, Date startTime, Date endTime);

	public Integer getAppAlertCount(String appId, Date startTime, Date endTime);

	public Map<String, Map<String, Long>> getAppAlertCountByType(String appId, String serviceId, Date startTime, Date endTime);

	public Map<String, Map<String, Long>> getAlertCountBySeverity(String appId, String serviceId, Date startTime, Date endTime);

	public Map<String, Map<String, Object>> getAlertByServiceAndSeverity(List<String> servIdList, Date startTime, Date endTime, int severity);

	public Map<String, Map<String, Long>> getAlertCountBySeverity(String groupBy, Date startTime, Date endTime);

	public Map<String, Map<String, Long>> getAlertCountByType(String groupBy, Date startTime, Date endTime);

}
